﻿
'Build 206. Version 1.1.207.4 Final 
'03/08/2010
'Deep Sky Labs

Imports System.Windows.Interop
Imports System.Runtime.InteropServices
Imports System.Windows.Threading

Imports Stardust.Core
Imports Stardust.Core.Controls
Imports Stardust.Core.Render

Class Window1

    Public ErrC As New ErrorConsole

    Public Enum ViewStyleEnum
        Scatter
        Wrap
    End Enum

    <DllImport("DwmApi.dll")> _
    Public Shared Function DwmExtendFrameIntoClientArea(ByVal hwnd As IntPtr, _
                                                       ByRef pMarInset As MainFrmMARGINS) As Integer
    End Function

#Region "Variables"
    Public MyArgs() As String = {}

    'Bookmarkin variables
    Dim bSections As New Dictionary(Of String, String) 'Bookmark Sections
    Dim CurSection As New List(Of ImageObject) 'Current Bookmark Section
    Dim CurTitle As String
    Private ViewStyle As ViewStyleEnum = ViewStyleEnum.Wrap

    'Main Windows Delegates

    Delegate Sub PrevUpdater(ByVal Source As Uri)
    Delegate Sub ExtImgUpdater(ByVal Source As Uri)

    Delegate Sub ScriptExecuter(ByVal File As String)
    Delegate Sub StatusUpdater(ByVal Visibility As Visibility)


    'Windows
    Private WithEvents bmManager As New BookmarkManager
    Private WithEvents ExtManager As New InstallExtension


#End Region

#Region "Functions"

    Public Sub LoadListOfImages(ByVal Files As List(Of String))
        'ListBox1.Items.Clear()
        For Each Str As String In Files
           
            Dim _c As New ImageObject(New Uri(Str, UriKind.RelativeOrAbsolute))

            _c.OriginalUri = New Uri(Str, UriKind.RelativeOrAbsolute)
            ListBox1.Items.Add(New ImageControl(_c))
        Next
    End Sub

    Public Sub LoadListOfImages(ByVal Files As List(Of Uri))
        For Each item In Files
            Dim _image As New ImageObject(item)
            Images.Add(_image)
            ListBox1.Items.Add(New ImageControl(_image))
        Next
    End Sub

    Public Sub LoadFolder(ByVal Folder As String)

        Dim timer As New System.Diagnostics.Stopwatch
        timer.Start()
        Dim dir As New IO.DirectoryInfo(Folder)
        Dim files = From item In dir.GetFiles _
                    Select item.FullName, item.Name, item.Extension, item.Exists _
                    Where Extension = ".JPG" Or Extension = ".jpg" _
                    Or Extension = ".png" Or Extension = ".bmp" Or Extension = ".gif" _
                    And Exists = True
                    Order By Name Ascending

        For Each item In files
            Dim _image As New ImageObject(New Uri(item.FullName, UriKind.RelativeOrAbsolute))
            _image.OriginalUri = New Uri(item.FullName, UriKind.RelativeOrAbsolute)

            Images.Add(_image)
            ListBox1.Items.Add(New ImageControl(_image))

        Next

        timer.Stop()
        DebugPrint(String.Format("Elapsed {0} milliseconds while loading folder {1}", timer.Elapsed.Milliseconds, dir.FullName))

    End Sub

    Private Sub UpdateBookmarkSection(ByVal Items As List(Of ImageObject))
        If Not (CurTitle = "") Then
            Try
                Dim file As String = bSections(CurTitle)
                Dim oldData As XDocument = XDocument.Load(file)

                'CurTitle = oldData.<ImageList>.@Title

                Dim od = From _image In oldData...<Image> _
                Select _image

                For Each item In od
                    Dim _i As New ImageObject(New Uri(item.Value, UriKind.RelativeOrAbsolute))
                    CurSection.Add(_i)
                    'ListBox2.Items.Add(New ImageControl(_i))

                Next

                Dim data = <?xml version="1.0" encoding="utf-8"?>
                           <ImageList Title=<%= CurTitle %>>
                               <%= From item As ImageObject In CurSection _
                                   Select <Image><%= item.ToString %></Image> %>
                           </ImageList>

                Dim sw As New IO.StreamWriter(file)
                sw.Write(data.ToString)
                sw.Close()
                CurSection.Clear()
            Catch ex As Exception
            End Try
        End If
    End Sub


    Public Sub LoadAlbum(ByVal File As IO.FileInfo)
        Dim xDoc As XDocument = XDocument.Load(File.FullName)

        CurTitle = xDoc.<ImageList>.@Title

        Dim data = From _image In xDoc...<Image> _
                   Select _image

        For Each item In data

            Dim _uri As New Uri(item.Value, UriKind.RelativeOrAbsolute)

            Dim _f As New IO.FileInfo(_uri.LocalPath)

            If _f.Exists Or _uri.IsFile = False Then
                Dim _i As New ImageObject(_uri)
                Images.Add(_i)
                ListBox1.Items.Add(New ImageControl(_i))
            End If

        Next
    End Sub

    Public Sub LoadAlbum(ByVal AlbumStr As String)
        Dim xDoc As XDocument = XDocument.Parse(AlbumStr)

        CurTitle = xDoc.<ImageList>.@Title

        Dim data = From _image In xDoc...<Image> _
                   Select _image

        For Each item In data

            Dim _uri As New Uri(item.Value, UriKind.RelativeOrAbsolute)

            Dim _f As New IO.FileInfo(_uri.LocalPath)

            If _f.Exists Or _uri.IsFile = False Then
                Dim _i As New ImageObject(_uri)
                Images.Add(_i)
                ListBox1.Items.Add(New ImageControl(_i))
            End If

        Next
    End Sub

    Public Sub RunScript(ByVal File As String)
        'First we most ask to user if he want to run the script. 
        Dim [continue] As Boolean = False
        Dim SettingStr As String = GetSetting("Stardust", "SecAnswer", File, "True")

        Dim Ask As Boolean = True
        Ask = [Boolean].Parse(SettingStr)

        If Ask = True Then
            Dim dlg As New SecurityDialog
            If dlg.ShowDialog = Forms.DialogResult.OK Then
                [continue] = True
                If dlg.DontAsk = True Then
                    SaveSetting("Stardust", "SecAnswer", File, False)
                End If
            Else
                [continue] = False

            End If

        Else
            [continue] = True
        End If

        If [continue] = True Then
            Try
                Dim SelScript As New IO.FileInfo(File)
                CurScript = New CintieFramework.Script(SelScript)

                Dim vars As New Dictionary(Of String, String)

                Try

                    Dim sc As New CintieFramework.ScriptContext
                    'Build and set the script variables

                    Dim _selImages As New List(Of Uri)
                    For Each item As ImageObject In Me.SelImages
                        _selImages.Add(item.OriginalUri)
                    Next

                    sc.Vars.Add("_selImg", CurPic)
                    sc.Vars.Add("_selImages", _selImages)
                    sc.Vars.Add("_theme", Application.Current.Resources)
                    sc.Vars.Add("_resourcesDir", SelScript.FullName & ".storage" & "\")

                    sc.MainFunction = "_result"

                    'Console.WriteLine(CurScript.Execute(sc))
                    'For Each Str As String in

                    Dim _result As List(Of Uri) = CurScript.Execute(Of List(Of Uri))(sc)
                    For Each item In _result
                        DebugPrint(item.AbsoluteUri, CurScript.ScriptInformation.Title)
                    Next

                    LoadListOfImages(_result)
                Catch ex As Exception
                    DebugPrint(ex.Message, CurScript.ScriptInformation.Title)
                End Try

            Catch ex As Exception
                DebugPrint(ex.Message)
            End Try
        End If


    End Sub

    Public Sub UpdateExtImage(ByVal Uri As Uri)
        Dim img As New Image
        Try
            img.Width = 50
            img.Height = 50
            img.Stretch = Stretch.Uniform
            img.Source = LoadImage(Uri, BitmapCacheOption.OnLoad)
            ExtensionsList.Items.Add(img)
            Console.WriteLine(Uri.AbsoluteUri)
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
    End Sub

    Public Sub UpdateStatus(ByVal Visibility As Visibility)
        ProgressBar1.Visibility = Visibility
    End Sub

#End Region

#Region "Properties"
    Public ReadOnly Property SelImages As List(Of ImageObject)
        Get
            Dim _list As New List(Of ImageObject)
            For Each item As ImageControl In ListBox1.Items
                If item.Selected = True Then
                    _list.Add(item.Base)
                End If
            Next

            Return _list
        End Get
    End Property

    Public ReadOnly Property SelectedItem As ImageControl
        Get
            Dim SelItem As ImageControl = Nothing
            Select Case ViewStyle
                Case ViewStyleEnum.Scatter
                    Dim items = From item In ListBox1.Items

                    SelItem = DirectCast(items.Last, ImageControl)

                Case ViewStyleEnum.Wrap
                    SelItem = DirectCast(ListBox1.SelectedItem, ImageControl)
            End Select

            Return SelItem
        End Get
    End Property
#End Region

#Region "GUI Interaction"
    Private Sub ListBox1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs)
        Try
            
            ListBox1.SelectedItem.Background = Brushes.Transparent
            StardustButton3.Image = ListBox1.SelectedItem.Image

            Dim Items As New List(Of ImageControl)

            For Each item As ImageControl In ListBox1.SelectedItems
                item.Selected = True
            Next

        Catch ex As Exception

        End Try
    End Sub

    Private Sub FullScreen_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        FullScreen1.Show()
        FullScreen1.Visibility = Windows.Visibility.Visible
        FullScreen1.ShowImage(CurPic)
        If FullScreen1.ThumbsList.Items.Count = 0 Then
            FullScreen1.UpdateThumbs()
        End If
    End Sub

    Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        'Get the args 

       
        MyArgs = Environment.GetCommandLineArgs


        'Glass Effect
        Try
            Dim mainWindowPtr As IntPtr = New WindowInteropHelper(Me).Handle
            Dim mainWindowSrc As HwndSource = HwndSource.FromHwnd(mainWindowPtr)
            mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0)

            ' Get System Dpi 
            Dim desktop As System.Drawing.Graphics = System.Drawing.Graphics.FromHwnd(mainWindowPtr)
            Dim DesktopDpiX As Single = desktop.DpiX
            Dim DesktopDpiY As Single = desktop.DpiY

            ' Set Margins 
            Dim margins As New MainFrmMARGINS()

            ' Extend glass frame into client area 
            ' Note that the default desktop Dpi is 96dpi. The margins are 
            ' adjusted for the system Dpi. 
            margins.cxLeftWidth = Convert.ToInt32(5 * (DesktopDpiX / 96))
            margins.cxRightWidth = Convert.ToInt32(5 * (DesktopDpiX / 96))
            margins.cyTopHeight = Convert.ToInt32((CInt(Border1.ActualHeight) + 5) * (DesktopDpiX / 96))
            margins.cyBottomHeight = Convert.ToInt32(5 * (DesktopDpiX / 96))

            Dim hr As Integer = DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, margins)
            ' 
            If hr < 0 Then
                'DwmExtendFrameIntoClientArea Failed 
            End If
        Catch generatedExceptionName As DllNotFoundException
            ' If not Vista, paint background white. 
            Application.Current.MainWindow.Background = Brushes.White
        End Try
        'End Glass Effect

        'Chek if bookmarks directory exists
        Try
            Dim bDir As New IO.DirectoryInfo(StardustDir & "\Bookmarks")
            If bDir.Exists = False Then
                bDir.Create()
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


        Try
            'Check if OpenAtStart bookmark section exists, if don't, then create it.
            Dim atS As New IO.FileInfo(StardustDir & "\Bookmarks\OpenAtStart.sil")
            If atS.Exists = False Then
                Dim data = <?xml version="1.0" encoding="utf-8"?>
                           <ImageList Title="Open at start">
                               <!-- <Image>C:\images\image.jpg</Image> -->
                               <!-- <Image> http://www.images.com/image.jpg </Image>-->
                           </ImageList>
                Dim sw As New IO.StreamWriter(atS.FullName)
                sw.Write(data.ToString)
                sw.Close()
            End If

            LoadAlbum(atS)

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


        Try
            Dim sDir As New IO.DirectoryInfo(StardustDir & "\Scripts")
            For Each sfile As IO.FileInfo In sDir.GetFiles("*.cf")
                Scripts.Add(sfile.FullName)
                Dim scriptInfo As New CintieFramework.ScriptInformation(sfile.FullName)
                DebugPrint("Loading extension", scriptInfo.Title)
                Dispatcher.BeginInvoke(New ExtImgUpdater(AddressOf UpdateExtImage), _
                                        Windows.Threading.DispatcherPriority.Background, _
                                        scriptInfo.ImageUri)

                DebugPrint(scriptInfo.ImageUri.AbsoluteUri, scriptInfo.Title)
            Next
        Catch ex As Exception

        End Try

        Try
            Dim sd As New IO.DirectoryInfo(StardustDir & "\bookmarks")
            If sd.Exists = False Then
                sd.Create()
            End If

            For Each Sectionfile As IO.FileInfo In sd.GetFiles("*.sil") 'Stardust image List
                Try
                    Dim xDoc As XDocument = XDocument.Load(Sectionfile.FullName)
                    Dim title As String = xDoc.<ImageList>.@Title
                    bSections.Add(title, Sectionfile.FullName)

                    Dim AlbumPreview As New Stardust.Core.Controls.AlbumPreview With
                        {.Height = 45, .Width = 170, .AlbumTitle = title, .AlbumBase = title}

                    Dim PrevList As List(Of Uri) =
                        (From item In xDoc...<ImageList>.<Image> Select New Uri(item.Value)
                         Take 3).ToList

                    AlbumPreview.FillPreview(PrevList)

                    BookmarkList.Items.Add(AlbumPreview)


                    BookmarksCombo.Items.Add(title)
                Catch ex As Exception

                End Try
            Next

        Catch ex As Exception

        End Try

        'Initial functions: 

        'Load style 
        If My.Settings.SkinFile <> "" Then
            Dim ThemeFile As New IO.FileInfo(My.Settings.SkinFile)

            If ThemeFile.Exists Then
                Dim Style As ResourceDictionary =
                            LoadXaml(Of ResourceDictionary)(My.Settings.SkinFile)

                My.Application.Resources = Style
            End If

        End If

        If MyArgs.Length > 1 Then
            Dim ArgFile1 As New IO.FileInfo(MyArgs(1))

            'MsgBox(ArgFile1.FullName)

            Select Case ArgFile1.Extension
                Case ".sext"
                    'Install the script

                    Try

                        Dim ScriptsDir As New IO.DirectoryInfo(StardustDir & "\Scripts")
                        Dim ZipFile As String = Environment.GetCommandLineArgs(1)
                        DebugPrint(String.Format("Extracting file {0} to {1}", ZipFile, ScriptsDir.FullName))

                        Dim MainScriptFile As String = ""

                        Using zip1 As Ionic.Zip.ZipFile = Ionic.Zip.ZipFile.Read(ZipFile)
                            'Add the handler here
                            Dim Entry As Ionic.Zip.ZipEntry

                            For Each Entry In zip1
                                Entry.Extract(ScriptsDir.FullName, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently)
                                Dim _fi As New IO.FileInfo(Entry.FileName)
                                If _fi.Extension = ".cf" Then
                                    MainScriptFile = String.Format("{0}\{1}", ScriptsDir.FullName, _fi.Name)
                                End If
                            Next
                        End Using


                        'Add item to Scripts list
                        Scripts.Add(MainScriptFile)

                        'Add item to list
                        Dim file As New IO.FileInfo(MainScriptFile)
                        Dim s As New CintieFramework.ScriptInformation(file.FullName)

                        DebugPrint(s.ImageUri.AbsoluteUri, s.Title)

                        Dispatcher.BeginInvoke(New ExtImgUpdater(AddressOf UpdateExtImage), _
                        Windows.Threading.DispatcherPriority.Background, _
                        s.ImageUri)

                        TabControl1.TabIndex = 2
                    Catch ex As Exception
                        MsgBox(ex.Message)
                    End Try

                Case ".sil"
                    Dim ArgUri As New Uri(ArgFile1.FullName)
                    If ArgUri.IsFile Then
                        LoadAlbum(ArgFile1)
                    Else
                        Try
                            Dim _Client As New System.Net.WebClient
                            Dim Data As String = _
                                _Client.DownloadString(ArgUri)

                            LoadAlbum(Data)
                        Catch ex As Exception

                        End Try
                    End If

            End Select

        End If


    End Sub


    Private Sub mnu_LoadFolder_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

        Dim Open As New System.Windows.Forms.FolderBrowserDialog
        If Open.ShowDialog = Forms.DialogResult.OK Then

            Dispatcher.BeginInvoke(New StatusUpdater(AddressOf UpdateStatus), _
                                   Windows.Threading.DispatcherPriority.Background, _
                                   Visibility.Visible)

            LoadFolder(Open.SelectedPath)

            Dispatcher.BeginInvoke(New StatusUpdater(AddressOf UpdateStatus), _
                                   Windows.Threading.DispatcherPriority.Background, _
                                   Visibility.Hidden)
        End If
    End Sub


    Private Sub findTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs)
        ListBox1.Items.Clear()

        Dim _f As New List(Of String)
        Dim _l As New List(Of IO.FileInfo)

        For Each item As ImageObject In Images
            _l.Add(New IO.FileInfo(item.OriginalUri.LocalPath))
        Next

        Dim _q = From file As IO.FileInfo In _l _
        Select file.Name, file.FullName _
        Where Name.Contains(findTextBox.Text) _
        Order By Name Ascending

        For Each item In _q
            _f.Add(item.FullName)
        Next
       
        LoadListOfImages(_f)
    End Sub


    Private Sub btn_DoBookmark_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        
        For Each item As ImageObject In Me.SelImages
            CurSection.Add(item)
        Next
        UpdateBookmarkSection(CurSection)

    End Sub



    Private Sub InstallScript_Click(ByVal sender As System.Object, _
                                                      ByVal e As System.Windows.RoutedEventArgs)
        Dim ScriptsDir As New IO.DirectoryInfo(StardustDir & "\Scripts")
        'Check if Scripts Dir exists
        If ScriptsDir.Exists = False Then
            'if not exists, create it
            ScriptsDir.Create()
        End If

        Dim dlg As New System.Windows.Forms.OpenFileDialog
        dlg.Filter = "Stardust Extension (*.sext)|*.sext" 'Stardust Extension
        If dlg.ShowDialog = Forms.DialogResult.OK Then

            Dim ZipFile As String = dlg.FileName
            DebugPrint(String.Format("Extracting file {0} to {1}", ZipFile, ScriptsDir.FullName))

            Dim MainScriptFile As String = ""

            Using zip1 As Ionic.Zip.ZipFile = Ionic.Zip.ZipFile.Read(ZipFile)
                'Add the handler here
                Dim Entry As Ionic.Zip.ZipEntry

                For Each Entry In zip1
                    Entry.Extract(ScriptsDir.FullName, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently)
                    Dim _fi As New IO.FileInfo(Entry.FileName)
                    If _fi.Extension = ".cf" Then
                        MainScriptFile = String.Format("{0}\{1}", ScriptsDir.FullName, _fi.Name)
                    End If
                Next
            End Using



            'Add item to Scripts list
            Scripts.Add(MainScriptFile)

            'Add item to list
            Dim file As New IO.FileInfo(MainScriptFile)
            Dim s As New CintieFramework.ScriptInformation(file.FullName)

            Dispatcher.BeginInvoke(New ExtImgUpdater(AddressOf UpdateExtImage), _
            Windows.Threading.DispatcherPriority.Background, _
            s.ImageUri)

        End If


    End Sub

    Private Sub ExtensionsList_SelectionChanged(ByVal sender As System.Object, _
                                                ByVal e As System.Windows.Controls.SelectionChangedEventArgs) _
                                            Handles ExtensionsList.SelectionChanged

        If ExtensionsList.SelectedIndex >= 0 Then
            Dim _f As String = Scripts(ExtensionsList.SelectedIndex)
            DebugPrint(String.Format("Trying to run script at {0}", _f))
            Dispatcher.BeginInvoke(New StatusUpdater(AddressOf UpdateStatus), _
                                   Windows.Threading.DispatcherPriority.Background, _
                                   Visibility.Visible)

            Dispatcher.BeginInvoke(New ScriptExecuter(AddressOf RunScript), _
                               Windows.Threading.DispatcherPriority.Background, _
                               _f)
            ExtensionsList.SelectedIndex = -1
            Dispatcher.BeginInvoke(New StatusUpdater(AddressOf UpdateStatus), _
                                   Windows.Threading.DispatcherPriority.Background, _
                                   Visibility.Hidden)
        End If

    End Sub

    Private Sub ManageBookmarks_MouseLeftButtonDown(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        bmManager.Show()
    End Sub

    Private Sub ClearList_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Images.Clear()
        ListBox1.Items.Clear()
    End Sub

    Private Sub ScriptsDir_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Try
            System.Diagnostics.Process.Start(StardustDir & "\Scripts")
        Catch ex As Exception

        End Try
    End Sub

    Private Sub SkinsWindow_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Dim wnd As New Skin
        wnd.Show()
    End Sub

    Private Sub MoreExtensions_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        ExtManager.ShowAndLoad()
    End Sub

    ''' <summary>
    ''' To interact with the bookmark manager Window
    ''' </summary>
    ''' <param name="list"></param>
    ''' <remarks></remarks>
    Private Sub UpdateBookmarkSections(ByVal list As Dictionary(Of String, String)) Handles bmManager.ListUpdated
        'The List of bookmark section is composed by the title of the section and its FullName in HardDrive

        bSections = list
        BookmarkList.Items.Clear()
        BookmarksCombo.Items.Clear()

        For Each item In list
            Dim Album As New Album(New Uri(item.Value))
            Dim AlbumPreview As New Core.Controls.AlbumPreview With
                {.AlbumBase = Album.AlbumTitle, .Height = 45, .Width = 170, .AlbumTitle = Album.AlbumTitle}
            AlbumPreview.FillPreview(Album.PreviewImages)

            BookmarkList.Items.Add(AlbumPreview)
            BookmarksCombo.Items.Add(item.Key)

        Next
    End Sub
    ''' <summary>
    ''' To interact with the Extension Installer Window
    ''' </summary>
    ''' <param name="Exts"></param>
    ''' <remarks></remarks>
    Private Sub UpdatedExtensions(ByVal Exts As List(Of String)) Handles ExtManager.UpdatedExtensions
        Scripts.Clear()
        ExtensionsList.Items.Clear()
        For Each Ext In Exts
            Scripts.Add(Ext)
            Dim ExtInfo As New CintieFramework.ScriptInformation(Ext)

            Dispatcher.BeginInvoke(Sub()
                                       Dim img As New Image
                                       img.Width = 50
                                       img.Height = 50
                                       img.Stretch = Stretch.Uniform

                                       Try
                                           img.Source = LoadImage(ExtInfo.ImageUri, BitmapCacheOption.OnDemand)
                                       Catch ex As Exception
                                           img.Source = LoadImage(New Uri("Images\error.png", UriKind.RelativeOrAbsolute))
                                       End Try

                                       ExtensionsList.Items.Add(img)

                                   End Sub,
                                   Windows.Threading.DispatcherPriority.Background)
        Next

    End Sub

    Private Sub BookmarkList_SelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles BookmarkList.SelectionChanged
        Try
            CurTitle = BookmarkList.SelectedItem.ToString

            'Load the images in the Bookmark Section
            If BookmarkList.Items.Count > 0 Then
                'For Each item In bSections
                '    Console.WriteLine(String.Format("{0}, {1}", item.Key, item.Value))
                'Next
                Dim file As String = bSections(BookmarkList.SelectedItem.ToString)
                LoadAlbum(New IO.FileInfo(file))
                BookmarkList.SelectedIndex = -1
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub StardustButton9_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        System.Diagnostics.Process.Start("http://www.deepskylabs.com/stardust/help")
    End Sub

    Private Sub StardustButton10_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        System.Diagnostics.Process.Start("http://www.deepskylabs.com/stardust/share")
    End Sub

    Private Sub StardustButton11_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        System.Diagnostics.Process.Start("http://www.deepskylabs.com/stardust/news")
    End Sub

    Private Sub mnuSelectAll_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        For Each item As ImageControl In ListBox1.Items
            item.Selected = True
        Next
    End Sub

    Private Sub mnuDeselectAll_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        For Each item As ImageControl In ListBox1.Items
            item.Selected = False
        Next
    End Sub

    Private Sub BookmarksCombo_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles BookmarksCombo.SelectionChanged
        CurTitle = BookmarksCombo.SelectedItem.ToString
    End Sub
#End Region


End Class


